package edu.ntu.cloudroid.server;

import java.io.IOException;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.ntu.cloudroid.model.PMF;
import edu.ntu.cloudroid.model.profile.ProfileData;

public class DeleteData extends HttpServlet {
	@SuppressWarnings("unchecked")
	@Override
	protected synchronized void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("deleting..");
		PersistenceManager pm = PMF.get().getPersistenceManager();

		
		pm.currentTransaction().begin();
		Query q = pm.newQuery(ProfileData.class);
		System.out.println(q.deletePersistentAll());
		
		/*int i = 1000;
		for (String key : (List<String>) q.execute()) {
			pm.d
			if (0 == --i)
				break;
		}*/
		pm.currentTransaction().commit();
		System.out.println("done");
		//resp.getWriter().println(0 == i ? "done" : "continue");
	}
}
